package com.xhj.controller;

import com.xhj.service.VODService;
import com.xhj.util.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(value="阿里云视频点播管理")
@RestController
@CrossOrigin
@RequestMapping("/vod/")
public class VODController {

    @Autowired
    private VODService vodService;

    @ApiOperation(value = "视频上传")
    @RequestMapping("upload")
    public ResultEntity uploadVideo(
            @ApiParam(name = "file",value = "视频文件",required = true)
            @RequestBody MultipartFile file){
        String videoId = vodService.uploadVideo(file);
        return ResultEntity.successWithData().data("videoId",videoId);
    }

    @ApiOperation(value = "根据Id删除云端视频")
    @RequestMapping("delete/{videoId}")
    public ResultEntity deleteById(
            @ApiParam(name = "videoId", value = "云端视频id", required = true)
            @PathVariable("videoId") String videoId){
        vodService.deleteVideoById(videoId);
        return ResultEntity.successWithoutData();
    }

    @ApiOperation(value = "根据多个Id删除云端视频")
    @RequestMapping("deleteAll")
    public ResultEntity deleteVideoList(
            @ApiParam(name = "videoIdList", value = "云端视频id", required = true)
            @RequestParam("videoIdList") List<String> videoIdList){
        vodService.deleteVideoList(videoIdList);
        return ResultEntity.successWithoutData();
    }

    @ApiOperation(value = "获得视频播放凭证")
    @RequestMapping("getPlayAuth/{videoId}")
    public ResultEntity getVideoPlayAuth(
            @ApiParam(name = "videoId", value = "云端视频id", required = true)
            @PathVariable("videoId") String videoId){
        String playAuth = vodService.getPlayAuth(videoId);
        return ResultEntity.successWithData().data("playAuth",playAuth);
    }

}
